cmake_minimum_required(VERSION 3.10)

#让CMake在构建时使用MinGW的编译器
set(CMAKE_C_COMPILER "C:/Program Files/mingw64/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/Program Files/mingw64/bin/g++.exe")

#设置编译器属性
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)   	# 强制要求编译器支持 C++11
set(CMAKE_CXX_EXTENSIONS OFF)         	# 禁用编译器扩展（如 GNU 扩展）

#指定项目名称
project(myapp)

#设置生成的目标的输出目录
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG  	"D:/testSubCmake/projTargetPath/Debug")		    
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE  "D:/testSubCmake/projTargetPath/Release")
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG  	"D:/testSubCmake/projTargetPath/Debug")		
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE  "D:/testSubCmake/projTargetPath/Release")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG  	"${CMAKE_BINARY_DIR}/../bin/Debug")		   
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE  "${CMAKE_BINARY_DIR}/../bin/Release")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG  	"${CMAKE_BINARY_DIR}/../bin/Debug")		
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE  "${CMAKE_BINARY_DIR}/../bin/Release")

# 设置默认构建类型，如果没通过命令 cmake --build build --config Release 指定
if(NOT CMAKE_BUILD_TYPE)
    #set(CMAKE_BUILD_TYPE Debug)  # 默认为 Debug
    set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)  # 构建Release
endif()

#添加子项目
add_subdirectory("D:/testSubCmake/subProj" subProj)

# 指定头文件，测试独立链接sqlite库
#include_directories(D:/testSubCmake/sqlite/include)

# 添加可执行文件
add_executable(myapp main.cpp)

# 链接子项目的库
target_link_libraries(myapp PRIVATE subProj)

# 测试独立链接sqlite库
#if (CMAKE_BUILD_TYPE AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
#    target_link_directories(myapp PRIVATE D:/testSubCmake/sqlite/bin/Release)  #路径有空格时最好加引号
#else ()
#    target_link_directories(myapp PRIVATE D:/testSubCmake/sqlite/bin/Debug)  #路径有空格时最好加引号
#endif ()
#target_link_libraries(myapp PRIVATE libsqlite3.dll.a)